package cn.codeforfun.initialization.server.model;

import cn.codeforfun.initialization.server.annotation.UniqueHost;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

import static cn.codeforfun.initialization.server.ServerConstants.UNINSTALL;

/**
 * 服务器信息
 *
 * @author wangbin
 */
@Entity
@Table
@Getter
@Setter
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Server implements Serializable {

    private static final long serialVersionUID = -2237010714196294443L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /**
     * 服务器地址
     */
    @NotBlank(message = "服务器地址不能为空")
    @Pattern(message = "服务器地址不正确", regexp = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
    @Column(unique = true)
    @UniqueHost
    private String host;

    /**
     * 别名，备注
     */
    private String name;

    /**
     * ssh端口号
     */
    private Integer port = 22;

    /**
     * 服务器用户名
     */
    @NotBlank(message = "用户名不能为空")
    private String username;

    /**
     * 服务器密码
     */
    @NotBlank(message = "密码不能为空")
    private String password;


    private String dockerFlag = UNINSTALL;
    private String dockerVersion;

    private String kubectlFlag = UNINSTALL;
    private String kubectlVersion;

    private String helmFlag = UNINSTALL;
    private String helmVersion;

    private String osId;
    private String osVersionId;
    private String osPrettyName;
    private String osKernelVersion;

    private Date createAt = new Date();
}
